
function ListNode(val, next) {
    this.val = (val===undefined ? 0 : val)
    this.next = (next===undefined ? null : next)
}

// 迭代
// 时间复杂度：O(n)
// 空间复杂度：O(1)
function printListIter(head) {
    while (head != null) {
        console.log(head.val)
        head = head.next
    }
}

// 递归
function printList(head) {
    if (head == null) return

     console.log(head.val)

    printList(head.next)
}


